
<!-- 配送商申请准入页面 -->
<template>
  <div>
    <el-container class="qualification-create">
      <el-header>
        <el-form
          :inline="true"
          :model="applyHospitalForm"
          ref="ruleForm"
          :rules="applyHospitalRules"
        >
          <el-form-item
            label="申请准入医院"
            prop="accessHospital">
            <el-select
              v-model="applyHospitalForm.accessHospital"
              filterable
              remote
              placeholder="搜索选择项"
              :remote-method="(e)=>remoteMethod(e,'hospital')"
              @change="getRemoteHospitalOptions"
              @focus="getRemotePersonOptions"
            >
              <el-option
                v-for="items in applyHospitalNameOptions"
                :key="items.id"
                :title="items.name"
                :label="items.name"
                :value="items.id"
              />
            </el-select>
          </el-form-item>
        </el-form>
      </el-header>
      <el-tabs
        v-model="activeName"
        @tab-click="handleClick">
        <!-- 企业信息 -->
        <el-tab-pane
          class="tab-pane-first"
          label="企业信息"
          name="first">
          <!-- title信息 -->
          <RecordInfo
            :record-form="enterpriseInfoList.enterpriseInfo"
            :record-data="enterpriseInfoData.enterpriseData"
          >
            <template slot="businessScope">
              <el-checkbox-group v-model="enterpriseInfoData.enterpriseData['businessScope']">
                <el-checkbox
                  v-for="item in businessScope"
                  :key="item.key"
                  :label="item.key"
                  disabled
                >{{ item.label }}</el-checkbox>
              </el-checkbox-group>
            </template>
            <span />
          </RecordInfo>
          <h3 class="title">财务信息</h3>
          <!-- 财务信息 -->
          <RecordInfo
            :record-form="enterpriseInfoList.financeInfo"
            :record-data="enterpriseInfoData.financeData"
          />
          <!-- <h3 class="title">证照信息</h3> -->
          <div class="cardWallTitle">
            <p class="card-title">证照信息</p>
            <div>
              <span>请为该分组选择资质证书</span>
              <span class="total">已选择{{ productList.length+registerList.length }}项</span>
              <el-button
                type="text"
                @click="clearAll">清空</el-button>
            </div>
          </div>
          <div class="card-box">
            <div
              @click="addProduct(0)"
              class="licenceCard cardAdd">
              <div>
                <p class="cardAddIcon">+</p>
                <p class="cardAddTxt">添加证照</p>
              </div>
            </div>
            <el-card
              class="licenceCard"
              v-for="(i,index) in productList"
              :key="'p'+index">
              <pic-info-card
                :card-data="i"
                :idx="index"
                :card-type="cardType['delete']"
                :pic-type="picType['product']"
                @sendDelete="deleteCompanyList"
              />
            </el-card>
          </div>
          <h3 class="title">补充信息</h3>
          <RecordInfo
            :record-form="enterpriseInfoList.addInfo"
            :record-data="enterpriseInfoData.addData"
          />
        </el-tab-pane>
        <!-- 销售信息 -->
        <el-tab-pane
          label="销售员"
          class="tab-pane-second"
          name="second">
          <el-form
            :inline="true"
            :model="addPersonForm"
            ref="ruleForm">
            <el-form-item
              label="添加销售员"
              prop="salePerson">
              <el-select
                v-model="addPersonForm.salePerson"
                filterable
                remote
                placeholder="搜索选择"
                :remote-method="(e)=>remoteMethod(e,'person')"
                @change="addSalePersonList"
                @focus="focusSalePersonList"
              >
                <el-option
                  v-for="items in addPersonOptions"
                  :key="items.id"
                  :title="items.userName?items.userName:items.loginName"
                  :label="items.userName?items.userName:items.loginName"
                  :value="items.id"
                />
              </el-select>
            </el-form-item>
          </el-form>
          <div
            v-for="(item,index) in salePersonLicence"
            :key="index">
            <h3 class="title">
              销售员信息
              <el-button
                type="text"
                style="color: red; margin-right:16px;"
                @click="removeOneSalePerson(index)"
              >删除</el-button>
            </h3>
            <RecordInfo
              :record-form="enterpriseInfoList.saleOrderInfo"
              :record-data="item" />
            <h3 class="top-title">身份证信息</h3>
            <RecordInfo
              :record-form="enterpriseInfoList.idInfo"
              :record-data="item" />
            <div
              class="licence-box"
              v-viewer>
              <div
                class="licence-every-box"
                v-for="(it,index) in item.licenceInfo"
                :key="index">
                <div class="licence-url-box">
                  <el-image
                    style="width: 250px; height: 150px;"
                    :src="it.url"
                    fit="cover" />
                </div>
                <div class="licence-button-box">
                  <span>
                    <el-button
                      type="text"
                      @click="previewFile(it,it.url,index)">查看</el-button>
                  </span>
                  <span>
                    <el-button
                      type="text"
                      @click="downloadFile(it.url)">下载</el-button>
                  </span>
                </div>
              </div>
            </div>
            <div class="cardWallTitle">
              <p class="top-title">授权书</p>
              <div>
                <span>请为该分组选择资质证书</span>
                <span class="total">已选择{{ item.productList.length+item.registerList.length }}项</span>
                <el-button
                  type="text"
                  @click="clearAll(item,'salePerson')">清空</el-button>
              </div>
            </div>
            <div class="card-box">
              <div
                @click="addProduct(0,item,'salePerson',index)"
                class="licenceCard cardAdd">
                <div>
                  <p class="cardAddIcon">+</p>
                  <p class="cardAddTxt">添加授权书</p>
                </div>
              </div>
              <el-card
                class="licenceCard"
                v-for="(i,ins) in item.productList"
                :key="'p'+ins">
                <pic-info-card
                  :card-data="i"
                  :idx="ins"
                  :card-type="cardType['delete']"
                  :pic-type="picType['product']"
                  @sendDelete="(ind,i)=>deleteCompanyList(ind,i,'salePerson',index)"
                />
              </el-card>
            </div>
          </div>
        </el-tab-pane>
        <!-- 申请准入产品 -->
        <el-tab-pane
          label="申请准入产品"
          class="tab-pane-third"
          name="third">
          <!-- 11111111111111111111111 -->
          <el-form
            ref="wholesalepurchase"
            :inline="true"
            class="demo-ruleForm"
            :model="wholesalepurchase"
          >
            <el-form-item label="注册证号">
              <el-input
                placeholder="请输入"
                v-model="wholesalepurchase.registerNo" />
            </el-form-item>
            <el-form-item label="院内编码">
              <el-input
                placeholder="请输入"
                v-model="wholesalepurchase.hosProdCode" />
            </el-form-item>
            <el-form-item label="产品编码">
              <el-input
                placeholder="请输入"
                v-model="wholesalepurchase.distributorProdCode" />
            </el-form-item>
            <el-form-item label="产品名称">
              <el-input
                placeholder="请输入"
                v-model="wholesalepurchase.chName" />
            </el-form-item>
            <el-form-item label="生产厂家">
              <el-input
                placeholder="请输入"
                v-model="wholesalepurchase.productionFactory" />
            </el-form-item>
            <el-form-item>
              <el-button @click="resetForm">
                <i class="el-icon-refresh-right" />
                重置
              </el-button>
              <el-button
                @click="productQuery"
                type="primary">
                <i class="el-icon-refresh-right" />
                查询
              </el-button>
            </el-form-item>
            <!-- 3222222222222222 -->
          </el-form>
          <div class="remove-btn">
            <div>
              <el-button
                type="text"
                @click="batchRemoveList">批量删除</el-button>
              <el-button
                type="primary"
                @click="addProductList">添加产品</el-button>
            </div>
          </div>
          <el-editable
            height="400"
            :data="firstTableData"
            :columns="responseAddColumns"
            @selection-change="handleSelectionChange"
          >
            <template
              slot="default-hosProdCode"
              slot-scope="{row}">
              <div style="display:flex;">
                <el-select
                  filterable
                  remote
                  placeholder="请输入院内编码"
                  :disabled="!row.isEditcode"
                  :remote-method="remoteRequestAsync"
                  :loading="hosProdCodeLoading"
                  @focus="getRowHosProdId(row)"
                  @change="gethosProdId"
                  v-model="row.hosProdCode"
                >
                  <el-option
                    v-for="item in hosProdCodeList"
                    :key="item.companyProdCode"
                    :label="item.companyProdCode"
                    :value="item.companyProdCode"
                  />
                </el-select>
                <el-button
                  v-if="!row.isEditcode"
                  size="small"
                  @click.stop="editHosProdCode(row)"
                  type="text text-primary"
                >编辑</el-button>
                <el-button
                  v-else
                  size="small"
                  @click.stop="updateHosProdCodeById(row)"
                  type="text text-primary"
                >确定</el-button>
              </div>
            </template>
            <template
              slot="default-registerNo"
              slot-scope="scope">
              <div>
                <cell-registration
                  :key="scope.row.registerNo"
                  :regis-no="scope.row.registerNo"
                  :content="'注册证已过期，点击查看详细信息'"
                  :status="scope.row.expireStatus"
                  :regis-data="scope.row.registInfo"
                />
              </div>
            </template>
            <template
              slot="default-action"
              slot-scope="{row}">
              <el-button
                type="text text-danger"
                @click="removeOneList(row)">删除</el-button>
            </template>
            <!-- 查看资质 -->
            <template
              slot="default-qualiFication"
              slot-scope="{row}">
              <el-button
                type="text"
                @click="Seebtn(row)">查看</el-button>
            </template>
            <!-- 查看历史记录 -->
            <template
              slot="default-historyRecord"
              slot-scope="{row}">
              <el-button
                type="text"
                @click="seeHistoryList(row)">查看</el-button>
            </template>
            <!-- 查看注册证号 存在问题 后台字段暂不确定 v-viewer -->
            <!-- <div
              slot="default-registerNo"
              slot-scope="scope">
              <el-button
                size="small"
                @click="viewCertificate(scope.row.companyName)"
                type="text"
              >{{ scope.row.registerNo }}</el-button>

            </div> -->
          </el-editable>
          <el-pagination
            align="right"
            style="margin-top:10px;"
            @size-change="sizeChange"
            @current-change="pageChange"
            :current-page="page.curPage"
            :page-sizes="page.PAGE_NUMBER"
            :page-size="page.pageSize"
            :layout="page.PAGINATION_LAYOUT"
            :total="page.totalElements"
          />
        </el-tab-pane>
      </el-tabs>
      <div
        v-viewer
        ref="registration"
        class="registration"
        v-show="false">
        <el-image
          style="width: 250px; height: 150px;"
          :src="registUrl"
          fit="cover" />
      </div>
      <!-- 选择证照弹框 -->
      <el-dialog
        class="showLicences"
        :visible.sync="showLicences"
        :before-close="initArr"
        :show-close="true"
        width="90%"
        @close="handleDialogClose"
      >
        <div
          class="picture-corver"
          v-if="previewLicenceFlag">
          <div>
            <span
              slot="footer"
              class="dialog-header">
              <el-input
                v-model="keyword"
                placeholder="请输入关键字" />
              <el-button
                type="primary"
                @click="dialogSearch"
                :class="{'isAddWidth':submitLoading}"
                :loading="submitLoading"
              >
                <i
                  class="el-icon-search"
                  :class="{'isdisplay':submitLoading}" />
                {{ submitLoading?'':'查询' }}
              </el-button>
              <el-button @click="resetDialog">
                <i class="el-icon-refresh-right" />
                重 置
              </el-button>
            </span>
          </div>
          <div
            class="fixed-height"
            :style="dialogAutoHeight">
            <div
              class="licences-group"
              v-if="!isPicture">
              <h3 class="certificatesCard-header">证照组</h3>
              <div class="licences-card-corver">
                <!-- 证照组列表 -->
                <el-card
                  class="certificatesCard groupCard"
                  v-for="(i,index) in nowGroups"
                  :key="'g'+index"
                >
                  <template slot="header">
                    <p class="content-text">数量：{{ i.count }}</p>
                    <el-checkbox
                      class="cardCheck"
                      v-model="i.checked" />
                  </template>
                  <p class="content-text">组名：{{ i.groupName }}</p>
                  <p class="content-text">组编号：{{ i.groupCode }}</p>
                  <div class="showMore">
                    <el-button
                      type="text"
                      @click="previewGroupLicence(i)">查看</el-button>
                  </div>
                </el-card>
                <div
                  class="placeholder-card"
                  v-for="item in Math.floor(nowGroups.length / 2)"
                  :key="item"
                />
              </div>
            </div>
            <!-- 证照列表 -->
            <h3 class="certificatesCard-header">证照</h3>
            <div class="licences-card-corver">
              <el-card
                class="licenceCard"
                v-for="(i,index) in nowList"
                :key="'c'+index">
                <!-- 这里稍后需要添加 :isCheck='true'-->
                <pic-info-card
                  :card-data="i"
                  :card-type="cardType['add']"
                  :idx="index"
                  :licence-type="i.isRegister ? 'register':'normal'"
                  @sendIdx="changeProduct"
                />
              </el-card>
              <div
                class="placeholder-card place-piece"
                v-for="item in Math.floor(nowList.length / 2)"
                :key="item"
              />
            </div>
            <div
              v-if="!nowGroups.length && !nowList.length"
              class="no-data">暂无数据</div>
          </div>
          <div class="btn-area">
            <el-button @click="initArr">
              <i class="el-icon-circle-close" />
              取 消
            </el-button>
            <el-button
              type="primary"
              @click="addLicence">
              <i class="el-icon-circle-check" />
              确 定
            </el-button>
          </div>
        </div>
        <div
          v-else
          v-loading="previewLoading">
          <h3>添加证照</h3>
          <div class="pack-header">
            <p>
              <span class="pack-header-label">组名</span>
              <span class="pack-hedaer-text">{{ packInfoDetail.groupName }}</span>
              <span class="pack-header-label">编号</span>
              <span class="pack-hedaer-text">{{ packInfoDetail.groupCode }}</span>
            </p>
          </div>
          <div
            class="fixed-height"
            :style="dialogAutoHeight">
            <div class="licences-card-corver">
              <el-card
                class="licenceCard"
                v-for="(i,index) in previewLicenceArr"
                :key="'c'+index">
                <pic-info-card :card-data="i" />
              </el-card>
            </div>
          </div>
          <div class="group-licence-back">
            <el-button
              type="primary"
              @click="packGoBack">
              <i class="el-icon-back" />
              返回
            </el-button>
          </div>
        </div>
      </el-dialog>
      <!-- 添加产品弹框 -->
      <el-dialog
        title="添加产品"
        width="1200px"
        :visible="dialogVisibel"
        @close="closeDialog">
        <SearchForm
          show-collapse
          :data="computedProductListSearchForm"
          :compact-data="compactProductListSearchForm"
          @searchForm="searchForm"
          @resetForm="resetForm"
          ref="search"
          @remoteMethod="(e)=>remoteMethod(e,'upEnterprise')"
        />
        <el-editable
          height="400"
          :data="dialogTableData"
          :columns="dialogColumns"
          @selection-change="dialogHandleSelectionChange"
          @select-all="allinarr(selection)"
          v-loading="dialogTableDataLoading"
        >
          <template
            slot="default-registerNo"
            slot-scope="scope">
            <div>
              <cell-registration
                :key="scope.row.registerNo"
                :regis-no="scope.row.registerNo"
                :content="'注册证已过期，点击查看详细信息'"
                :status="scope.row.expireStatus"
                :regis-data="scope.row.registInfo"
              />
            </div>
          </template>
        </el-editable>
        <el-footer>
          <el-pagination
            align="right"
            class="pagination"
            @size-change="dialogHandleSizeChange"
            @current-change="dialogHandleCurrentChange"
            :current-page="dialogPageList.curPage"
            :page-sizes="dialogPageList.PAGE_NUMBER"
            :page-size="dialogPageList.pageSize"
            :layout="dialogPageList.PAGINATION_LAYOUT"
            :total="dialogPageList.totalElements"
          />
        </el-footer>
        <div
          slot="footer"
          class="dialog-footer">
          <el-button @click="cancelDialog">取消</el-button>
          <el-button
            type="primary"
            @click="confirmDialog">确定</el-button>
        </div>
      </el-dialog>
      <el-dialog
        title="历史记录"
        width="800px"
        :visible="dialogHistoryVisibel"
        @close="closeHistoryDialog"
      >
        <el-container>
          <el-editable
            height="400"
            :data="[]"
            :columns="dialogHistoryColumns" />
        </el-container>
      </el-dialog>
    </el-container>
  </div>
</template>
<script>
import {
  qualificationGetLicences,
  qualificationGetMergeLicence,
  qualificationGetLicenGroups,
  qualificationGetGroupLicences
} from '@const/api'
import { hasIn, cloneDeep, isArray } from 'lodash'
import ElEditable from '@components/el-editable'
import SearchForm from '@components/businesscomponents/search'
import CellRegistration from '@/moduleComponents/common/detail/cell-registration'
import {
  enterpriseInfo,
  financeInfo,
  addInfo,
  saleOrderInfo,
  idInfo,
  commonProductListSearchForm,
  dialogColumns,
  responseAddColumns,
  dialogHistoryColumns,
  businessScope
} from './const'
import picInfoCard from '@/moduleComponents/distributorSide/distributionAdmittance/picInfoCard'
import {
  hospitalHosCooperationProdList,
  enumSelectorhosDealerUpEnterpriseSelector,
  enumSelectorhosDealerSuperDealer,
  getCertificate
} from '@const/productCenterApiV2'
import {
  companyhostopalList,
  companygetAcCompanyInfoAll,
  acAuthQualificationGgetBySalar,
  acAuthQualificationGetByCompany,
  comProdItemfindProdItemByHos,
  companygetAcCompanyInfoAdd,
  acAuthSalegetList,
  authSupplierHospitaladmittanceSubmit,
  orderBackUcMerchantIdentityUsergetById,
  commonPcAdmittanceTemporarysaveList,
  commonPcAdmittanceTemporarygetLike,
  commonPcAdmittanceTemporarydelCompileIds,
  hospitalistHosProducts,
  relateProdDistributorAndHospital,
  commonPcAdmittanceTemporaryupdate,
  pcHosDistributorProdApplyGetApplyProdByConstrict
} from '@const/beforeSettleApi'
import { urlDownload } from '@const/utils.js'
import paginationMixin from '@mixins/paginationMixin'
import RecordInfo from '@/moduleComponents/beforeSettle/distributorSide/purchasingManagement/rowLayout'
// import RecordInfo from '@/moduleComponents/beforeSettle/distributorSide/purchasingManagement/record'
import { PAGE_NUMBER, PAGINATION_LAYOUT, fitType } from '@const/common'
const cardType = { delete: '0', add: '1', read: '2', allType: '3' }
// 删除的图片列表的类型
const picType = { company: '0', product: '1', register: '2' }
export default {
  name: 'QualificationCreate',
  mixins: [paginationMixin],
  components: {
    picInfoCard,
    RecordInfo,
    SearchForm,
    ElEditable,
    CellRegistration
  },
  data () {
    return {
      dialogTableDataLoading: true,
      selection: false, // 全选状态改变时
      registUrl: '',
      editid: '',
      temporary: [],
      salespersonList: [],
      emporaryenterprise: [],
      filgas: '', // 如果没有销售员授权书为假
      saleQualifications: [], // 获取销售员信息集合
      companyQualifications: [], // 获取入参企业证照信息
      businessScope, // 经营业务范围
      timeout: null, // 延时
      hosProdCodeLoading: false,
      hosProdCodeList: [], // 院内编码下拉
      hosProdId: '', // 院内编码选择后取得产品id
      restaurants: [],
      state: '',
      SelectDatabtn: [],
      // 新增模糊搜索
      wholesalepurchase: {
        registerNo: '', // 注册证号
        hosProdCode: '', // 院内编码
        distributorProdCode: '', // 配送商编码
        chName: '', // 产品名称
        manufacturer: '' // 生产厂家
      },
      PcHosDistributorProdApply: [],
      rowProductcode: '',
      searchQuery: {},
      applyHospitalFormname: '',
      applyHospitalForm: {
        // 申请准入医院id
        accessHospital: '',
        // 申请准入医院名称
        accessHospitalname: ''
      },
      // 模糊搜索申请准入医院列表
      applyHospitalNameOptions: [],
      // 临时假数据
      addPersonOptions: [],
      // 证照信息
      licenceInfo: [],
      // 企业信息和销售员信息集合
      enterpriseInfoList: {
        enterpriseInfo,
        financeInfo,
        addInfo,
        saleOrderInfo,
        idInfo
      },
      // 企业信息和销售员信息
      enterpriseInfoData: {
        enterpriseData: {},
        financeData: {},
        addData: {},
        saleOrderData: {}
      },
      applyHospitalRules: {
        accessHospital: [
          { required: true, message: '请输入申请准入医院名称', trigger: 'change' }
        ]
      },
      PAGE_NUMBER, // 页码数组
      PAGINATION_LAYOUT, // 页码功能布局
      tableData: [],
      dialogVisibel: false,
      // 添加产品弹框查询项
      commonProductListSearchForm,
      // 销售员获取销售员信息集合
      saleInfoList: [],
      activeName: 'first',
      submitLoading: false,
      cardType, // picInfoCard的组件类型
      picType,
      showLicences: false, // 显示所有资质
      productList: [], // 产品资质列表
      registerList: [], // 注册证ID列表
      // 弹出框证照相关信息
      keyword: '', // 证照搜索keyword
      total: 0,
      nowList: [], // 当前弹窗中所有证照
      nowGroups: [], // 弹出框中的group
      checkedList: [],
      isPicture: 0,
      addPersonForm: {
        salePerson: ''
      },
      dialogHistoryColumns,
      dialogColumns,
      firstTableData: [],
      firstTableDataone: [],
      dialogPageList: {
        curPage: 1,
        PAGE_NUMBER,
        pageSize: PAGE_NUMBER[0],
        PAGINATION_LAYOUT,
        totalElements: 0
      },
      dialogTableData: [],
      dialogTableSelectData: [],
      responseAddColumns,
      tableSelectData: [],
      showimg: false,
      fitType,
      dialogHistoryVisibel: false,
      dialogType: '',
      dialogIndex: 0,
      previewLicenceFlag: true,
      previewLoading: false, // 预览的loading
      packInfoDetail: {
        groupName: '',
        groupCode: ''
      },
      previewLicenceArr: [],
      page: {
        curPage: 1,
        PAGE_NUMBER,
        pageSize: PAGE_NUMBER[0],
        PAGINATION_LAYOUT,
        totalElements: 0
      }
    }
  },
  created () {
    // 我是编辑再提交
    if (this.filgtype === '9') {
      this.initButton()
      this.getCompanyInfo()
      this.getSalarInfo()
      this.getProductLists()
      // 反显医院
      let objnameid = {}
      objnameid.id = this.ids
      objnameid.name = this.name
      this.applyHospitalNameOptions.push(objnameid)
      this.applyHospitalFormname = this.applyHospitalNameOptions[0].name
      if (this.$route.query.idsa === '8') {
        this.editid = ''
      } else {
        this.editid = this.$route.query.id
      }
      this.applyHospitalForm.accessHospital = this.ids
    } else {
      this.initButton()
      this.getList()
    }
  },
  mounted () {
    // this.requestToAddData('init')
  },
  computed: {
    distributorId () {
      return this.$route.query.distributorId
    },
    hospitalId () {
      return this.$route.query.hospitalId
    },
    id () {
      return this.$route.query.id
    },
    // 医院名称
    name () {
      return this.$route.query.name
    },
    // 医院id
    ids () {
      return this.$route.query.ids
    },
    // 编辑再提交状态
    filgtype () {
      return this.$route.query.filgtype
    },
    // 根据浏览器的高度计算dialog的高度
    dialogAutoHeight () {
      return {
        overflow: 'auto',
        height: '54vh'
      }
    },
    compactProductListSearchForm () {
      return this.computedProductListSearchForm.slice(0, 2)
    },
    // 计算查询条件表单
    computedProductListSearchForm () {
      return this.commonProductListSearchForm
    },
    // 销售员所有信息集合
    salePersonLicence () {
      this.saleInfoList.forEach(item => {
        if (item.gender === 1) {
          item.gender = '男'
        } else {
          item.gender = '女'
        }
        if (!isArray(item.productList)) {
          this.$set(item, 'productList', [])
        }
        if (!isArray(item.registerList)) {
          this.$set(item, 'registerList', [])
        }
        if (!isArray(item.licenceInfo)) {
          this.$set(item, 'licenceInfo', [
            {
              type: 'jpg',
              url: item.identityBack
            },
            {
              type: 'jpg',
              url: item.identityFront
            }
          ])
        }
        // 拼接有效日期
        this.$set(
          item,
          'dateRanges',
          `${item.startDate.split(' ')[0]} - ${item.endDate.split(' ')[0]}`
        )
      })
      return this.saleInfoList
    }
  },
  watch: {
    tableData: {
      immediate: true,
      handler (val) {
        this.page.total = val.length
      }
    }
  },
  methods: {
    // 编辑再提交 接口 start registNo
    startconfirmDialog () {
      this.SelectDatabtn = []
      this.dialogTableSelectData.forEach((item, index) => {
        let filterfield = {}
        filterfield.hosId = this.applyHospitalForm.accessHospital || ''
        filterfield.hosName = this.applyHospitalFormname || ''
        filterfield.hosProdCode = item.hosProdCode || ''
        filterfield.distributorProdCode = item.distributorProdCode || ''
        filterfield.productId = item.distributorProdItemId || ''
        filterfield.chName = item.chName || ''
        filterfield.spec = item.spec || ''
        filterfield.model = item.model || ''
        filterfield.unit = item.unit || ''
        filterfield.price = item.price || '0.00' // 根据后台要求没有就传0.00
        filterfield.registerNo = item.registNo || ''
        filterfield.registerNoId = '' || ''
        filterfield.productionFactory = item.manufacturerName || ''
        filterfield.productionFactoryId = '' || ''
        filterfield.supplier = item.upEnterpriseName || ''
        filterfield.supplierId = item.upEnterpriseId || ''
        filterfield.qualificationsId = '' || ''
        filterfield.proCode = item.platCode || ''
        filterfield.companyName = item.registUrl || ''
        filterfield.hosProdId = item.hosProdItemId || ''
        filterfield.companyId = this.$store.state.companyId || ''
        filterfield.qualifications = ''
        this.SelectDatabtn.push(filterfield)
      })
      this.$axios({
        method: 'post',
        url: commonPcAdmittanceTemporarysaveList,
        data: this.SelectDatabtn
      }).then(res => {
        if (res.data.code === '0') {
          this.requestToAddData()
        }
      })
      this.dialogVisibel = false
    },
    // 获取企业信息
    getCompanyInfo () {
      this.$axios({
        method: 'post',
        url: companygetAcCompanyInfoAll,
        data: {
          cid: this.distributorId
        }
      }).then(res => {
        if (hasIn(res, ['data', 'payload'])) {
          // title信息
          let data = res.data.payload.acCompanyBaseVo || {}
          if (data.businessScope) {
            data.businessScope = data.businessScope.split(',')
          }
          this.enterpriseInfoData.enterpriseData = data
          // 财务信息
          this.enterpriseInfoData.financeData =
            res.data.payload.acCompanyFinanceVo || {}
          // 补充信息
          this.enterpriseInfoData.addData =
            res.data.payload.acSupplementMessageVo || {}
        }
      })
    },
    // 获取企业证照
    getAcCompanyInfos () {
      this.$axios({
        url: acAuthQualificationGetByCompany,
        method: 'post',
        data: {
          hospitalId: this.hospitalId,
          orderid: this.id,
          distributorId: this.distributorId
        }
      })
        .then(res => {
          if (hasIn(res, ['data', 'payload'])) {
            let list = res.data.payload.companyQualifications || []
            let pdfReg = /\.(PDF|pdf)$/
            // productList 企业证照信息 this.productList
            this.emporaryenterprise = list && list.length ? list.map(item => {
              if (pdfReg.test(item.url)) {
                item.type = 'pdf'
              }
              return item
            })
              : []
            // 处理证照信息，详情只有图片展示，新增需要有其它信息
            this.emporaryenterprise.forEach(its => {
              this.salespersonList.forEach((it) => {
                if (its.url === it.url) {
                  this.productList.push(it)
                }
              })
            })
          }
        })
        .catch(err => {
          console.log(err, 'err')
        })
    },
    async getSalarInfo () {
      await this.$axios
        .post(qualificationGetLicences + '?page=0&size=1000', {
          companyId: this.$store.state.companyId,
          licences: [],
          keyword: this.keyword,
          productLicenceType: 0,
          type: 0
        }).then(res => {
          if (res.data.code !== '0') return
          this.salespersonList = res.data.payload.acCompanyLicenceVos
          this.getAcCompanyInfos()
        })
      this.$axios({
        url: acAuthQualificationGgetBySalar,
        method: 'post',
        data: {
          hospitalId: this.hospitalId,
          orderid: this.id,
          distributorId: this.distributorId
        }
      }).then(res => {
        if (hasIn(res, ['data', 'payload'])) {
          let salePersonList = res.data.payload
          if (salePersonList) {
            salePersonList.forEach((item, ind) => {
              if (isArray(item.saler)) {
                // 销售员授权书反显兼容
                item.saler.forEach(its => {
                  // 所有的授权书证照集合
                  if (this.salespersonList.length > 0) {
                    this.salespersonList.forEach((it) => {
                      if (its.url === it.url) {
                        this.temporary.push(it)
                      }
                    })
                  }
                })
              }
              this.addPersonForm.salePerson = item.name
              // productList 证照数据
              this.$set(item, 'productList', this.temporary)
              // 设置成功以后清空
              this.temporary = []
            })
            // this.saleInfoList 销售员 合集
            this.saleInfoList = salePersonList
          }
        }
      })
    },
    // 获取申明产品列表数据 lxy
    async getProductLists () {
      this.tableLoading = true
      await this.$axios({
        url: pcHosDistributorProdApplyGetApplyProdByConstrict,
        method: 'post',
        data: {
          constrictId: this.id,
          ...this.searchData
        }
      })
        .then(res => {
          if (hasIn(res, ['data', 'payload'])) {
            this.firstTableData = res.data.payload.content || []
            this.dialogTableSelectData = res.data.payload.content || []
            this.totalElements = res.data.payload.totalElements
          }
        })
        .finally(() => {
          this.tableLoading = false
        })
      // this.startconfirmDialog()
    },
    // 编辑再提交 接口 end
    // -----------院内编码 start-------------
    // 获取院内编码 当前数据的 hospitalId
    getRowHosProdId (item) {
      this.hosProdCodeList = []
      this.hosProdId = ''
    },
    // 院内编码模糊搜索后选择 把对应下拉中的产品id取出来
    gethosProdId (e) {
      let obj = this.hosProdCodeList.find(item => item.companyProdCode === e)
      this.hosProdId = obj.id ? obj.id : ''
    },
    // 编辑院内码
    editHosProdCode (row) {
      this.$set(row, 'isEditcode', true)
    },
    // 更新院内编码维护关系 platProdCode
    updateHosProdCodeById (row) {
      if (!this.hosProdId) {
        this.$set(row, 'isEditcode', false)
        return
      }
      this.$axios({
        method: 'post',
        url: relateProdDistributorAndHospital,
        data: {
          authItemId: row.productId,
          companyId: this.$store.state.companyId,
          companyProdId: '',
          hosProdId: this.hosProdId, // 按实际数据取值  产品id 下拉里面的 有疑问要确认 hospitalName
          hospitalId: row.hosId || this.applyHospitalForm.accessHospital,
          hospitalName: row.hosName,
          platProdCode: row.proCode
        }
      })
        .then(res => {
          if (res.data.code === '0') {
            this.$message({
              type: 'success',
              message: '编辑成功'
            })
            this.requestToAddData()
            this.$set(row, 'isEditcode', false)
          }
        })
        .finally(() => {
          // this.tableLoading = false
        })
      // commonPcAdmittanceTemporaryupdate  新增院内编码保存关系
      this.$axios({
        method: 'post',
        url: commonPcAdmittanceTemporaryupdate,
        data: {
          id: row.id,
          hosProdId: this.hosProdId, // 按实际数据取值  产品id 下拉里面的 有疑问要确认 hospitalName
          hosProdCode: row.hosProdCode
        }
      }).then(res => {
        console.log(res, '我是军杰的院内编码')
      })
    },
    // 院内编码远程搜索
    remoteRequestAsync (queryString) {
      clearTimeout(this.timeout)
      this.timeout = setTimeout(() => {
        this.remoteRequestSearch(queryString)
      }, 1000 * Math.random())
    },
    // 院内编码远程请求接口
    remoteRequestSearch (queryString) {
      if (!this.applyHospitalForm.accessHospital) {
        this.$message({
          type: 'warning',
          message: '请选择申请准入医院'
        })
        return
      }
      this.hosProdCodeLoading = true
      if (!queryString) return
      this.$axios({
        url: hospitalistHosProducts,
        method: 'post',
        data: {
          hospitalId: this.applyHospitalForm.accessHospital,
          hosProdCode: queryString
        }
      })
        .then(res => {
          if (hasIn(res, ['data', 'payload'])) {
            this.hosProdCodeList = res.data.payload ? res.data.payload : []
          }
        })
        .finally(() => {
          this.hosProdCodeLoading = false
        })
    },
    // -----------院内编码 end-------------

    initButton () {
      let obj = {}
      obj = {
        type: 'btn',
        arr: [
          {
            type: 'button',
            noReturn: true,
            val: '返回',
            handle: this.back
          },
          {
            type: 'primary',
            val: '保存草稿',
            handle: this.Savedraft
          },
          {
            type: 'primary',
            val: '提交',
            handle: this.preservation
          }
        ]
      }
      this.$store.commit('changeLayoutHandle', obj)
    },
    // 查询企业所有信息 companygetAcCompanyInfoAll
    getList () {
      this.$axios({
        method: 'post',
        url: companygetAcCompanyInfoAll,
        data: {
          cid: this.$store.state.companyId
        }
      }).then(res => {
        if (hasIn(res, ['data', 'payload'])) {
          // title信息
          let data = res.data.payload.acCompanyBaseVo || {}
          if (data.businessScope) {
            data.businessScope = data.businessScope.split(',')
          }
          this.enterpriseInfoData.enterpriseData = data
          // 财务信息
          this.enterpriseInfoData.financeData =
            res.data.payload.acCompanyFinanceVo || {}
          // 补充信息
          this.enterpriseInfoData.addData =
            res.data.payload.acSupplementMessageVo || {}
        }
      })
    },
    // 用户输入时获取到符合查询项的准入医院列表||销售员列表|| 查询供应商
    remoteMethod (e, type) {
      // 远程搜索医院
      if (type === 'hospital') {
        this.$axios({
          method: 'get',
          url: companyhostopalList,
          params: {
            type: 1,
            name: e
          }
        }).then(res => {
          this.applyHospitalNameOptions = res.data.payload
        })
        // 远程搜索 销售员
      } else if (type === 'person') {
        this.$axios({
          method: 'get',
          url: `${acAuthSalegetList}?name=${e}`,
          data: {
            name: e
          }
        }).then(res => {
          if (hasIn(res, ['data', 'payload'])) {
            this.addPersonOptions = res.data.payload
          }
        })
        // 远程搜索 供应商
      } else if (type === 'upEnterprise') {
        this.getAuthItemName(e)
      }
    },
    getRemoteHospitalOptions () {
      // 内容改变获取当前医院名称
      this.applyHospitalFormname = this.applyHospitalNameOptions.find(item => {
        return item.id === this.applyHospitalForm.accessHospital
      }).name // 医院名称
      this.requestToAddData()
    },
    // 查看历史记录弹框
    seeHistoryList (row) {
      this.dialogHistoryVisibel = true
    },
    // 查看注册证号   registration
    viewCertificate (url) {
      if (!url) {
        this.$message({
          type: 'warning',
          message: '没有有效的路径'
        })
        return
      }
      this.registUrl = url
      if (/\w(\.gif|\.jpeg|\.png|\.jpg|\.bmp)/i.test(url)) {
        setTimeout(() => {
          const viewer = this.$refs['registration'].$viewer
          viewer.view(0)
        }, 600)
        return
      }
      if (url.includes('.pdf')) {
        this.$pdfViewer({ url, title: 'pdf预览' })
      }
    },
    Seebtn (row) {
      this.$router.push({
        path:
          '/distributorSide/distributionAdmittance/productQualification',
        query: {
          distributorProdItemId: row.productId,
          id: 'filg',
          hospitalId: this.applyHospitalForm.accessHospital,
          hosProdCode: row.hosProdCode
        }
      })
    },
    // 点击证照弹窗，过滤已选，如果已选，就发送后端过滤
    addProduct (index, data, type, i) {
      this.isPicture = index
      this.dialogIndex = i
      let arr = []
      this.showLicences = true
      if (type === 'salePerson') {
        data.productList.forEach(e => {
          arr.push(e.id)
        })
        this.dialogType = 1
      } else {
        // 如果选择的是公司，则只有一个
        this.productList.forEach(e => {
          arr.push(e.id)
        })
        this.dialogType = 0
      }
      this.getLicences(0, arr, index)
      this.getLicenGroups()
    },
    // 选中取消弹窗的复选框
    changeProduct (i) {
      let p = this.nowList[i]
      if (this.checkedList.indexOf(p) === -1) {
        this.checkedList.push(p)
      } else if (!this.nowList[i].checked) {
        this.checkedList.splice(this.checkedList.indexOf(p), 1)
      }
    },
    packGoBack () {
      this.previewLoading = false
      this.previewLicenceFlag = true
    },
    // 重置数据
    initArr () {
      this.showLicences = false
      this.nowList = []
      this.checkedList = []
      this.nowGroups = []
    },
    // 弹窗的确认
    addLicence () {
      if (this.checkedList) {
        var licences = this.checkedList.map(e => {
          return e.id
        })
      }
      if (this.nowGroups) {
        var groups = this.nowGroups.filter(e => {
          if (e.checked) {
            return e.id
          }
        })
      }
      // 判断添加的数组
      this.getMergeLicence(groups, licences, this.isPicture, this.dialogType)
      // 清空选中项目
      this.initArr()
    },
    // 证照组数据获取
    getLicenGroups () {
      this.$axios
        .get(qualificationGetLicenGroups, {
          params: {
            companyId: this.$store.state.companyId,
            keyword: this.keyword
          }
        })
        .then(res => {
          let list = hasIn(res, 'data.payload') ? res.data.payload : []
          this.nowGroups = list.map(e => {
            return {
              checked: false,
              ...e
            }
          })
        })
    },
    dialogSearch () {
      this.initArr()
      this.addProduct(this.isPicture)
    },
    // 重置添加证照弹框
    resetDialog () {
      this.keyword = ''
    },
    // 删除对应的证照
    deleteCompanyList (ind, i, type, index) {
      i = parseInt(i)
      if (type) {
        if (i === 1) {
          this.salePersonLicence[index].productList.splice(ind, 1)
        } else {
          this.salePersonLicence[index].registerList.splice(ind, 1)
        }
        return
      }
      if (i === 1) {
        this.productList.splice(ind, 1)
      } else {
        this.registerList.splice(ind, 1)
      }
    },
    // 查看产品包详情
    previewGroupLicence (i) {
      this.previewLicenceFlag = false
      this.previewLoading = true
      this.packInfoDetail.groupName = i.groupName
      this.packInfoDetail.groupCode = i.groupCode
      this.$axios({
        method: 'get',
        url: qualificationGetGroupLicences,
        params: {
          groupId: i.id
        }
      })
        .then(res => {
          this.previewLoading = false
          let arr = hasIn(res, ['data', 'payload']) ? res.data.payload : []
          this.previewLicenceArr = arr
        })
        .catch(() => {
          this.previewLicenceFlag = true
        })
        .finally(() => {
          this.previewLoading = false
        })
    },
    // 清空证照
    clearAll (data, type) {
      // this.companyList = []
      if (type === 'salePerson') {
        data.productList = []
        data.registerList = []
        return
      }
      this.productList = []
      this.registerList = []
    },
    // 获取最终弹框的证照列表（非组）列表，如果本身就有后端过滤 companygetAcCompanyInfoAdd
    getLicences (val, licences, index) {
      this.submitLoading = true
      this.$axios
        .post(qualificationGetLicences + '?page=' + val + '&size=1000', {
          companyId: this.$store.state.companyId,
          licences: licences,
          keyword: this.keyword,
          productLicenceType: index,
          type: ''
        })
        .then(res => {
          let data = hasIn(res, 'data') ? res.data : {}
          let list = hasIn(res, 'data.payload') ? res.data.payload : {}
          this.totalElements = data.totalElements
          let finallyArr = []
          if (list.acCompanyLicenceVos && list.acCompanyLicenceVos.length > 0) {
            finallyArr = list.acCompanyLicenceVos
          }
          if (list.pcCertificateVos && list.pcCertificateVos.length > 0) {
            list.pcCertificateVos.forEach(item => {
              item.isRegister = true
            })
            finallyArr = list.pcCertificateVos
          }
          this.nowList = finallyArr.map(e => {
            // TODO 加入checked判断条件
            return {
              checked: false,
              ...e
            }
          })
        })
        .finally(() => {
          this.submitLoading = false
        })
    },
    // 预览图片
    previewFile (item, url, index) {
      // 如果图片链接可以使用 则暂时 否则提示不可用
      if (url.indexOf(':') >= 1) {
        let url = item.url
        const viewer = this.$el.querySelector('.licence-box').$viewer
        viewer.view(index)
      } else {
        this.$message({
          type: 'warning',
          message: '图片不可用'
        })
      }
    },
    // 下载图片、PDF
    downloadFile (url) {
      if (!url) return
      urlDownload(url)
    },
    dialogHandleSizeChange (size) {
      this.dialogPageList.pageSize = size
      this.dialogPageList.curPage = 1
      this.getProductList()
    },
    dialogHandleCurrentChange (curPage) {
      this.dialogPageList.curPage = curPage
      this.getProductList()
    },
    sizeChange (size) {
      this.page.pageSize = size
      this.page.curPage = 1
      this.requestToAddData()
    },
    pageChange (curPage) {
      this.page.curPage = curPage
      this.requestToAddData()
    },
    // 返回资质列表（根据选中的资质组和资质）
    getMergeLicence (groups, licences, index, dialogType) {
      // 遍历所有已选的内容的id
      let arr = []
      if (dialogType === 0) {
        this.productList.forEach(e => {
          arr.push(e.id)
        })
      }
      if (dialogType === 1) {
        this.salePersonLicence[this.dialogIndex].productList.forEach(e => {
          arr.push(e.id)
        })
      }
      this.$axios
        .post(qualificationGetMergeLicence, {
          chechedLicences: arr,
          groups: groups.map(item => item.id),
          licences: licences
        })
        .then(res => {
          let list = hasIn(res, 'data.payload') ? res.data.payload : []
          if (dialogType === 0) {
            this.productList = list.acCompanyLicenceVos || []
          } else if (dialogType === 1) {
            this.salePersonLicence[this.dialogIndex].productList =
              list.acCompanyLicenceVos || []
          }
        })
    },
    // 鼠标获取焦点时获取到所有销售员  orderBackUcMerchantIdentityUsergetById 根据id添加销售员 this.$store.state.companyName
    getRemotePersonOptions () {
      this.$axios({
        method: 'get',
        url: companyhostopalList,
        params: {
          type: 1
        }
      }).then(res => {
        if (hasIn(res, ['data', 'payload'])) {
          this.applyHospitalNameOptions = res.data.payload
        }
      })
    },
    // 销售员聚焦 获取所有销售员
    focusSalePersonList () {
      this.$axios({
        method: 'get',
        url: acAuthSalegetList,
        data: {}
      }).then(res => {
        if (hasIn(res, ['data', 'payload'])) {
          this.addPersonOptions = res.data.payload
        }
      })
    },
    // 销售员切换时需要调取接口获取销售员信息(销售员可以为一个或多个) addPersonForm.salePerson
    addSalePersonList () {
      let arrssst = this.addPersonOptions.find(item => {
        return item.id === this.addPersonForm.salePerson
      })
      this.$axios({
        method: 'get',
        url: `${orderBackUcMerchantIdentityUsergetById}?userId=${arrssst.id}`,
        data: {
          userId: arrssst.id
        }
      }).then(res => {
        if (res.data.code !== '0') return
        let objin = res.data.payload
        // 如果有一个为假 则提示身份证信息不全，请补全
        let Salesperson =
          objin.name &&
          objin.gender &&
          objin.nation &&
          objin.birthDate &&
          objin.identityId &&
          objin.address &&
          objin.issueOffice &&
          objin.startDate &&
          objin.identityBack &&
          objin.identityFront
        if (!Salesperson) {
          this.$message({
            type: 'warning',
            message:
              '该用户未完善身份证信息，不能选择。请联系该用户在个人中心完善身份证信息'
          })
          return
        }
        // 销售员去重
        if (this.saleInfoList.length < 1) {
          this.saleInfoList.push({ ...res.data.payload })
        } else {
          let filg = this.saleInfoList.some(item => {
            return item.userId === res.data.payload.userId
          })
          if (!filg) {
            this.saleInfoList.push({ ...res.data.payload })
          }
        }
        this.addPersonOptions.forEach(item => {
          if (item.id === arrssst.id) {
            this.saleInfoList.forEach(ite => {
              if (ite.userId === item.id) {
                this.$set(ite, 'phone', item.phone)
                this.$set(ite, 'mail', item.mail)
                this.$set(ite, 'genderStr', item.genderStr)
                this.$set(ite, 'gender', item.gender)
                this.$set(ite, 'name', item.userName)
              }
            })
          }
        })
      })
    },
    isShowImg () {
      const viewer = this.$el.querySelector('.images').$viewer
      viewer.show()
    },
    // 删除已选中的销售员信息
    removeOneSalePerson (ind) {
      this.saleInfoList = this.saleInfoList.filter((item, index) => {
        return ind !== index
      })
    },
    // 添加产品弹框获取产品列表  this.dialogPageList.pageSize
    getProductList () {
      this.dialogTableDataLoading = true
      if (!this.applyHospitalForm.accessHospital) {
        this.$message({
          type: 'warning',
          message: '请选择申请准入医院'
        })
        return
      }
      this.dialogVisibel = true
      const postData = {
        hospitalId: this.applyHospitalForm.accessHospital,
        page: this.dialogPageList.curPage,
        pageSize: this.dialogPageList.pageSize,
        ...this.searchQuery
      }
      const url = enumSelectorhosDealerUpEnterpriseSelector
      this.$axios({
        method: 'post',
        url: comProdItemfindProdItemByHos,
        data: postData
      }).then(res => {
        let obj = hasIn(res, 'data.payload') ? res.data.payload : {}
        this.dialogTableData = obj.content
        this.dialogPageList.totalElements = obj.totalElements
        this.dialogTableDataLoading = false
      })
    },
    back () {
      this.$router.go(-1)
    },
    // 提交  authSupplierHospitaladmittanceSubmit  0-待审核；1-已拒绝：2-已通过；3-已终止   6-草稿
    preservation () {
      if (!this.applyHospitalForm.accessHospital) {
        this.$message({ type: 'warning', message: '请选择申请准入医院' })
        return
      }
      if (!this.addPersonForm.salePerson) {
        this.$message({ type: 'warning', message: '请选择销售员' })
        return
      }
      if (!this.firstTableData) {
        this.$message({ type: 'warning', message: '请添加产品' })
        return
      }
      this.applyHospitalForm.accessHospitalname = this.applyHospitalNameOptions.find(
        item => {
          return item.id === this.applyHospitalForm.accessHospital
        }
      ).name
      this.totalNumberObtained(2)
    },
    // 保存草稿  authSupplierHospitaladmittanceSubmit  0-待审核；1-已拒绝：2-已通过；3-已终止   6-草稿
    Savedraft () {
      if (!this.applyHospitalForm.accessHospital) {
        this.$message({ type: 'warning', message: '请选择申请准入医院' })
        return
      }
      this.totalNumberObtained(1)
    },
    // 提交保存接口
    publicsavesubmit (num) {
      this.saleQualifications = [] // 清空销售员信息集合
      this.companyQualifications = [] // 清空入参企业证照信息
      // 获取入参企业证照信息
      this.productList.forEach(item => {
        this.companyQualifications.push({
          qualificationsId: item.id || '',
          licencecode: item.licenceCode || '',
          licencename: item.licenceName || '',
          url: item.url || ''
        })
      })
      // 获取销售员信息集合
      this.salePersonLicence.forEach(item => {
        if (isArray(item.productList)) {
          // 多个销售员不添加授权书的情况
          let salerobj = []
          if (item.productList.length === 0) {
            salerobj.push({
              salerId: item.userId // 销售员id
            })
          } else {
            item.productList.forEach(it => {
              salerobj.push({
                salerId: item.userId, // 销售员id
                qualificationsId: it.cid,
                licencecode: it.licenceCode,
                licencename: it.licenceName,
                url: it.url
              })
            })
          }
          this.saleQualifications.push({
            saler: salerobj
          })
        }
      })
      // 如果是提交 进行校验
      if (num === 2) {
        if (this.companyQualifications.length === 0) {
          this.$message({ type: 'warning', message: '请添加企业证照信息' })
          return
        }
        for (let i = 0; i < this.saleQualifications.length; i++) {
          this.filgas = this.saleQualifications[i].saler.every(it => {
            return it.qualificationsId
          })
          if (!this.filgas) {
            this.$message({ type: 'warning', message: '请添加销售员授权书信息' })
            return
          }
        }
      }
      // 获取选中医院的名称
      this.applyHospitalForm.accessHospitalname = this.applyHospitalNameOptions.find(
        item => {
          return item.id === this.applyHospitalForm.accessHospital
        }
      ).name
      // 添加产品的数组 distributorProdItemId
      if (this.firstTableDataone) {
        this.firstTableDataone.forEach(item => {
          console.log(item.hosProdId)
          const objquery = {}
          // objquery.distributorProdItemId = item.hosProdId || item.distributorProdItemId || '' // 配送商产品sku id
          objquery.distributorProdItemId = item.productId || '' // 配送商产品sku id
          objquery.distributorProdCode = item.distributorProdCode || '' // 配送商产品sku编码  对应产品编码
          objquery.hosProdItemId = item.hosProdId || '' // 医院产品sku id     传空字符串
          objquery.hosProdCode = item.hosProdCode || '' // 院内产品编码 手输入
          objquery.hospitalId = item.hosId || item.hospitalId || '' // 医院id
          objquery.hospitalName = item.hosName || item.hospitalName || ''// 医院名称
          objquery.distributorId = this.$store.state.companyId // 配送商id
          objquery.distributorName = this.$store.state.companyName // 配送商名称
          objquery.proCode = item.platCode || item.proCode || ''// 平台编码
          if (this.PcHosDistributorProdApply.length === 0) {
            this.PcHosDistributorProdApply.push(objquery)
          } else {
            let filg = this.PcHosDistributorProdApply.every(ite => {
              return ite.distributorProdItemId !== item.id
            })
            if (filg) {
              this.PcHosDistributorProdApply.push(objquery)
            }
          }
        })
      }
      const parData = {
        id: this.editid,
        authState: num, // 状态
        supplierId: this.$store.state.companyId, // 供应商ID
        supplierName: this.$store.state.companyName, // 供应商名称
        enterpriseId: this.applyHospitalForm.accessHospital, // 医院ID
        enterpriseName: this.applyHospitalForm.accessHospitalname, // 医院名称
        contactName: this.enterpriseInfoData.enterpriseData.linkMan, // 联系人
        contactNumber: this.enterpriseInfoData.enterpriseData.linkPhone, // 联系电话
        salerId: this.addPersonForm.salePerson, // 销售员ID
        pcHosDistributorProdApplyQuery: this.PcHosDistributorProdApply, // 添加产品的数组
        companyQualifications: this.companyQualifications, // 企业信息集合
        saleQualifications: this.saleQualifications,
        updatedBy: this.$store.state.realName
      }
      this.$axios({
        method: 'post',
        url: authSupplierHospitaladmittanceSubmit,
        data: parData
      }).then(res => {
        if (res.data.code === '0') {
          this.$router.push({
            path: '/distributorSide/distributionAdmittance'
          })
        }
      })
    },
    async totalNumberObtained (num) {
      await this.$axios({
        method: 'post',
        url: commonPcAdmittanceTemporarygetLike,
        data: {
          companyId: this.$store.state.companyId,
          page: 1,
          pageSize: 10e6,
          hosId: this.applyHospitalForm.accessHospital
        }
      }).then(res => {
        if (res.data.code !== '0') return
        if (res.data.payload.content) {
          this.firstTableDataone = [...res.data.payload.content]
        }
        this.publicsavesubmit(num)
      })
    },
    addProductList () {
      this.getProductList()
    },
    // 关闭历史记录弹框
    closeHistoryDialog () {
      this.dialogHistoryVisibel = false
    },
    // 添加产品勾选产品时触发 lxy
    dialogHandleSelectionChange (arr) {
      this.dialogTableSelectData = []
      this.dialogTableSelectData.push(...arr)
    },

    // 添加产品弹框点击确定时, lxy
    confirmDialog () {
      this.SelectDatabtn = []
      this.dialogTableSelectData.forEach((item, index) => {
        let filterfield = {}
        filterfield.hosId = this.applyHospitalForm.accessHospital || ''
        filterfield.hosName = this.applyHospitalFormname || ''
        filterfield.hosProdCode = item.hosCode || ''
        filterfield.distributorProdCode = item.code || ''
        filterfield.productId = item.id
        filterfield.chName = item.chName || ''
        filterfield.spec = item.spec || ''
        filterfield.model = item.model || ''
        filterfield.unit = item.unit || ''
        filterfield.price = item.price || '0.00' // 根据后台要求没有就传0.00
        filterfield.registerNo = item.registerNo || ''
        filterfield.registerNoId = '' || ''
        filterfield.productionFactory = item.manufacturerName || ''
        filterfield.productionFactoryId = '' || ''
        filterfield.supplier = item.upEnterpriseName || ''
        filterfield.supplierId = item.upEnterpriseId || ''
        filterfield.qualificationsId = '' || ''
        filterfield.proCode = item.platCode || ''
        filterfield.companyName = item.pictureUrl || ''
        filterfield.hosProdId = item.hosProdId || ''
        filterfield.companyId = this.$store.state.companyId || ''
        filterfield.qualifications = ''
        this.SelectDatabtn.push(filterfield)
      })
      this.$axios({
        method: 'post',
        url: commonPcAdmittanceTemporarysaveList,
        data: this.SelectDatabtn
      }).then(res => {
        if (res.data.code === '0') {
          this.requestToAddData()
        }
      })
      this.dialogVisibel = false
    },
    // 请求已添加的数据接口
    requestToAddData (init) {
      this.$axios({
        method: 'post',
        url: commonPcAdmittanceTemporarygetLike,
        data: {
          companyId: this.$store.state.companyId,
          page: this.page.curPage,
          pageSize: this.page.pageSize,
          hosId: this.applyHospitalForm.accessHospital,
          ...this.wholesalepurchase
        }
      }).then(res => {
        if (hasIn(res, ['data', 'payload'])) {
          this.firstTableData = res.data.payload.content
          if (init && this.firstTableData && this.firstTableData.length) {
            this.applyHospitalNameOptions = [].concat([
              {
                id: this.firstTableData[0].hosId,
                name: this.firstTableData[0].hosName
              }
            ])
            // this.applyHospitalForm.accessHospital = this.firstTableData[0].hosId //医院反显先去掉
          }
          this.page.totalElements = res.data.payload.totalElements
        }
      })
    },
    // 下载图片
    downloadUrl (url) {
      if (!url) return
      urlDownload(url)
    },
    // 删除产品,列表其中一个this.dialogTableData
    removeOneList (data) {
      let proData = []
      let productobj = {}
      productobj.productId = data.productId
      proData.push(productobj)
      this.commonMethod(proData)
    },
    // 批量删除产品  commonPcAdmittanceTemporarydelCompileIds
    batchRemoveList () {
      if (!this.tableSelectData.length) {
        this.$message({ type: 'warning', message: '请选择需要删除的产品' })
        return
      }
      // this.tableSelectData products:proData item.productId
      let proData = []
      this.tableSelectData.forEach(item => {
        let productobj = {}
        productobj.productId = item.productId
        proData.push(productobj)
      })
      this.commonMethod(proData)
    },
    commonMethod (proData) {
      this.$axios({
        method: 'post',
        url: commonPcAdmittanceTemporarydelCompileIds,
        data: proData
      }).then(res => {
        this.requestToAddData()
      })
    },
    handleClick () {},
    // 列表产品选中
    handleSelectionChange (arr) {
      this.tableSelectData = arr
    },
    allinarr (isflge) {
      this.selection = !isflge
    },
    // 添加产品弹框(查询)
    searchForm (condition) {
      this.dialogPageList.curPage = 1
      this.searchQuery = condition
      this.getProductList()
    },
    // 添加产品弹框(重置)
    resetForm (condition) {
      this.dialogPageList.curPage = 1
      this.searchQuery = condition
      this.wholesalepurchase = {}
      // this.getProductList()
    },
    // 产品(查询)
    productQuery () {
      this.requestToAddData()
    },
    // 取消 关闭弹框
    cancelDialog () {
      this.dialogTableSelectData = []
      this.dialogVisibel = false
    },
    // 企业授权书点击X还原展示栏
    handleDialogClose () {
      this.keyword = ''
      this.previewLoading = false
      this.previewLicenceFlag = true
    },
    // 关闭弹框
    closeDialog () {
      this.dialogTableSelectData = []
      this.$refs.search.reset()
      this.dialogVisibel = false
    },

    // 远程搜索(供应商)
    getAuthItemName (value) {
      const postData = {
        upEnterpriseName: value
      }
      const item = this.computedProductListSearchForm.find(
        item => item.key === 'upEnterpriseId'
      )
      this.$axios
        .$post(enumSelectorhosDealerUpEnterpriseSelector, postData)
        .then(res => {
          const nameList = res.payload.content
          const options = nameList.map(item => {
            return {
              label: item.value,
              value: item.id
            }
          })
          this.$set(item, 'options', options)
        })
        .catch(e => {})
        .finally(() => {})
    }
  }
}
</script>
<style lang="less" scope>
@import '~@assets/var.less';
.qualification-create {
  position: static !important;
  padding: 0 !important;
  background: rgb(255, 255, 255);
  .licenceCard .cardAddIcon::selection,
  .cardAddTxt::selection {
    user-select: none;
  }
  // 证照信息
  .licence-box {
    margin-top: 10px;
    display: flex;
    flex-wrap: wrap;
    .licence-every-box {
      width: 250px;
      height: 200px;
      margin-right: 20px;
      margin-bottom: 20px;
      border: 1px solid #ccc;
      .licence-button-box {
        display: flex;
        align-items: center;
        height: 50px;
        border-top: 1px solid #ccc;
        span {
          text-align: center;
          display: block;
          width: 50%;
          height: 80%;
        }
        span:first-child {
          border-right: 1px solid #ccc;
        }
      }
      .licence-url-box {
        width: 250px;
        height: 150px;
        display: flex;
        justify-content: center;
        align-items: center;
        .iconfont {
          font-size: 60px;
        }
      }
    }
  }
  .remove-btn {
    display: flex;
    justify-content: flex-end;
    padding-right: 26px;
  }
  .title {
    border-bottom: 1px solid #eef0f5;
    padding: 15px 20px;
    margin-bottom: 20px;
    font-size: 16px;
    font-weight: bold;
    color: rgba(38, 52, 76, 0.8);
    text-align: left;
    position: relative;
    button {
      position: absolute;
      right: 16px;
    }
  }
  .top-title {
    padding: 15px 20px;
    margin-bottom: 20px;
    font-size: 16px;
    font-weight: bold;
    color: rgba(38, 52, 76, 0.8);
  }
  .showLicences {
    .el-dialog__header {
      padding: 0;
    }
    .no-data {
      text-align: center;
      margin-top: 30px;
    }
  }

  .cardWallTitle {
    padding: 10px 20px 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;

    .card-title {
      font-size: 20px;
      font-weight: 600;
    }

    .total {
      margin: 0 24px 0 12px;
    }
  }
  .card-box {
    padding: 20px;
  }
  .licences-card-corver {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    font-size: 0;

    .licenceCard {
      font-size: 14px;
    }
    .certificatesCard {
      font-size: 14px;
    }
    .placeholder-card {
      width: 277px;
      display: inline-block;
      vertical-align: bottom;
      margin: 10px;
    }
    .place-piece {
      margin: 10px;
      width: 374px;
    }
  }
  .fixed-height {
    margin: 20px 0;
  }
  .certificatesCard-header {
    margin: 15px 0 10px 0;
  }
  .certificatesCard {
    display: inline-block;
    width: 277px;
    border-radius: 0;
    box-shadow: initial;
    margin: 10px;
    position: relative;
  }
  .delete {
    color: #e24156;
  }
  .dialog-header {
    display: flex;
    padding-bottom: 10px;
    border-bottom: 1px solid rgb(220, 220, 220);
    margin-bottom: 10px;
    .el-input {
      width: 201px;
      margin-right: 6px;
    }
  }
  .licenceCard {
    display: inline-block;
    width: 376px;
    border-radius: 0;
    box-shadow: initial;
    margin: 0 16px 20px 0;
    position: relative;
  }
  .cardAdd {
    display: inline-block;
    min-height: 207px;
    border: 1px solid #ebeef5;
    cursor: pointer;
    div {
      position: absolute;
      text-align: center;
      width: 100%;
      .cardAddIcon {
        margin-top: 40px;
        line-height: 80px;
        font-size: 80px;
        color: #2371c5;
      }
      .cardAddTxt {
        font-size: 12px;
        opacity: 0.8;
      }
    }
  }
  .btn-area {
    display: flex;
    justify-content: flex-end;
  }
}
</style>
